#include "Game.h"
#include "GameState\GSMainMenu.h"
//#include "GameState\GSBattleMode3D.h"

Device* Game::m_D = 0;
SchoolBattle* Game::m_SB = 0;
GameState* Game::m_PrevState = 0;
std::list<GameState*> Game::m_StateList;

bool Game::isUpdateCalled = false; //To avoid calling Render before Update

Game::Game()
{
	m_D = new Device(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_NAME);
	m_SB = new SchoolBattle();
	DEBUG_LOG("GAME CLASS INIT\n");
	//let's try
	m_StateList.clear();
	m_StateList.push_front((GameState*)new GSMainMenu());
	m_StateList.front()->OnEnter();
}

Game::~Game()
{
	DEBUG_LOG("GAME CLASS DESTROYED!");
}

void Game::Run()
{
	m_SB->Update();
	m_SB->Render();
}
//Destroy state and creates a new one
void Game::SetState(GameState* newState)
{
	isUpdateCalled = false;
	m_StateList.front()->OnExit();
	m_StateList.pop_front();
	m_StateList.push_front(newState);
	m_StateList.front()->OnEnter();
}
//Retains previous state and create new state
void Game::PushState(GameState* newState)
{
	isUpdateCalled = false;
	m_StateList.front()->OnExit();
	m_StateList.push_front(newState);
	m_StateList.front()->OnEnter();
}
//Destroys current state and goes back to previous state
void Game::PopState()
{
	isUpdateCalled = false;
	m_StateList.front()->OnExit();
	m_StateList.pop_front();
	m_StateList.front()->OnEnter();
}

void Game::Exit()
{
	DEVICE->GetInstance()->closeDevice();
}